﻿namespace Dcms.Common
{
    using System;
    using System.Net;
    using System.Net.Mail;
    using System.Text;
    using System.Configuration;

    public class sendEmail
    {
        public static readonly string strAccount = ConfigurationManager.AppSettings["mailUserName"];
        public static readonly string strHost = ConfigurationManager.AppSettings["smtpServer"];
        public static readonly string strPwd = ConfigurationManager.AppSettings["mailPassWord"];

        public static bool sendMail(string to, string title, string content, string strFrom)
        {
            SmtpClient _smtpClient = new SmtpClient();
            _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            _smtpClient.Host = strHost;
            _smtpClient.Credentials = new NetworkCredential(strAccount, strPwd);
            MailMessage _mailMessage = new MailMessage(strFrom, to);
            _mailMessage.Subject = title;
            _mailMessage.Body = content;
            _mailMessage.BodyEncoding = Encoding.UTF8;
            _mailMessage.IsBodyHtml = true;
            _mailMessage.Priority = MailPriority.High;
            try
            {
                _smtpClient.Send(_mailMessage);
                return true;
            }
            catch (Exception ex)
            {
                Log.LogHandler.LogError("Dcms.Common.sendEmail.sendMail", ex);
                return false;
            }
        }
    }
}

